<template>
	<view>
		<h2>{{message.title}}</h2>
		<view style="padding-top: 20rpx;">
			<u-parse :content="message.content" @preview="preview" @navigate="navigate"></u-parse>
		</view>
		<view style="text-align: right;padding-right: 20rpx;">
			{{message.time}}
		</view>
	</view>
</template>
<script>
	import uParse from '@/components/u-parse/u-parse.vue'

	export default {
		components: {
			uParse
		},
		data() {
			return {
				id: 0,
				message: {},
				article: '<div>我是HTML代码</div>'
			}
		},
		methods: {
			//获取通知
			getData() {
				uni.request({
					url: 'http://localhost/dev-api/user/message/' + this.id,
					method: 'GET',
					header: {
						authorization: getApp().globalData.token
					},
					success: (resp) => {
						if (resp.data.code == 200) {
							console.log(resp.data);
							this.message = resp.data.data;
						} else {
							uni.showToast({
								title: '服务器繁忙',
								icon: 'none'
							})
						}
					},
					fail: (resp) => {}
				})
			},
			//更新数据为已读
			updata() {
				uni.request({
					url: 'http://localhost/dev-api/user/message',
					data: {
						id: this.id,
						read: 1
					},
					method: 'PUT',
					header: {
						authorization: getApp().globalData.token
					},
					success: (resp) => {
						if (resp.data.code == 200) {
							console.log(resp.data);
						}
					},
					fail: (resp) => {}
				})
			},
			preview(src, e) {
				// do something
			},
			navigate(href, e) {
				// do something
			}
		},
		onLoad(e) {
			this.id = e.id;
		},
		onShow() {
			this.getData();
			this.updata();
		}
	}
</script>

<style>
	@import url("@/components/u-parse/u-parse.css");
</style>